package com.neuedu.web.dao;

import com.neuedu.web.common.BaseDao;
import com.neuedu.web.po.CheckitemPO;
import com.neuedu.web.po.CheckitemPO;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * @author 金山
 * 项目：jdbc-dao
 * site: https://blog.fulfill.com.cn
 * 描述  dept 表的数据访问对象
 * @data  2024年11月21日13:38:03
 */
public class CheckItemDao extends BaseDao<CheckitemPO> {



    public List<CheckitemPO> selectAll(  String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectAll(CheckitemPO.class , sql,params);
    }
    public List<CheckitemPO> selectPage( int current, int size, String sql, Object... params) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return super.selectPage(CheckitemPO.class , current ,size,sql,params);
    }



    public CheckitemPO selectById(long id) throws NoSuchFieldException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {


        String sql = "select * from checkitem where check_id =  ?";
        return super.selectOne(CheckitemPO.class,sql,id);

    }



    public int insert(CheckitemPO checkitemPO) {
        String sql = "INSERT INTO  `checkitem` (   `name`, `price`) VALUES(  ?,? )  ";
        int count = super.update(sql,
                checkitemPO.getName(),
                checkitemPO.getPrice()

        );

        return count;

    }


    public int update(CheckitemPO po) {
        StringBuffer sql = new StringBuffer();

        sql.append(" update 					");
        sql.append("   `checkitem` 			");
        sql.append(" set			");
        sql.append("   `name` = ?,			");
        sql.append("   `price` = ?			");

        sql.append(" where `check_id` =  ?			");


        int count = super.update(sql.toString(),
                po.getName(),
                po.getPrice(),
                po.getCheckId()
        );

        return count;

    }

    /**
     * 通用的方法
     *
     * @return
     */

    public int delete(long id) {
        StringBuffer sql = new StringBuffer();

        sql.append(" delete from checkitem where check_id = ?");

        int count = super.update(sql.toString(),   id        );

        return count;

    }


}
